package com.njlime.cms.repository.app;

import com.njlime.cms.entities.InformationComment;
import com.njlime.cms.entities.InformationMotion;
import com.njlime.core.base.repository.impl.BaseDaoImpl;
import com.njlime.core.helper.PageBean;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Dean on 2017-10-17.
 */
@Repository
public class AppInformationMotionDaoImpl extends BaseDaoImpl<InformationMotion> {


    /**
     * 获取情绪
     * @param id
     * @param user_id
     * @return
     */
    public InformationMotion getInformationMotion(int id, int user_id){
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("select * from t_information_motion where information_id = ? and member_id = ? ");
        arrList.add(id);
        arrList.add(user_id);
        return findOne(sb.toString(),arrList);
    }

    /**
     * 获取情绪
     * @param id
     * @return
     */
    public Map<String,Object> getMostMotion(int id){
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("select count(*) count,motion from t_information_motion where information_id = ? group by motion order by count desc limit 1 ");
        arrList.add(id);
        List<Map<String,Object>> list = getListJdbc(sb.toString(),arrList);
        if(list != null){
            return list.get(0);
        }
        return null;
    }

}
